﻿@{ var memberInfo = ViewBag.Member as Himall.Model.UserMemberInfo;}

<script src="~/Scripts/jquery.cookie.js"></script>
<script src="~/Scripts/CommonJS.js"></script>
<script src="~/Scripts/jQuery.mouseDelay.min.js"></script>
<script src="~/Scripts/jquery.scrollLoading.min.js"></script>
<script src="~/Scripts/jquery.nicescroll.min.js"></script>
<link href="~/Areas/Web/Content/WebLoginPlug.css" rel="stylesheet" />
<link href="~/Areas/Web/Content/WebAlertPlug.css" rel="stylesheet" />
<script src="~/Areas/Web/Scripts/jQuery.Web.Alert.js"></script>
<script src="~/Areas/Web/Scripts/jQuery.Web.Login.js"></script>
@*<div>@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffffff")</div>*@
@{Html.RenderAction( "TopInfo" , "ProductPartial" );}
<div class="header">
    <div class="search-bar cl">
        <div class="logo"><a href="/"><img src="@ViewBag.Logo" height="60" alt="Himall" /></a></div>
        <!--<div class="my-shop">
            <div class="dropdown-btn"> 
                <a target="_blank" href="">购物车</a><b></b>
            </div>
        </div>-->
        <div class="search">
            <div class="search-form">
				<ul>
					<li>商品</li>
					<li>店铺</li>
				</ul>
				<label>商品</label>
				<input type="text" id="searchBox" class="text" name="" value="" placeholder="@ViewBag.Keyword" />
				<input type="button" id="searchBtn" class="button" value="搜索" />
            </div>
            <div class="hot-search">
                @{
                    int i = 0;
                }
                <strong>热门搜索：</strong>
                @foreach (var hotKey in ViewBag.HotKeyWords)
                {
                    if (i++ == 0)
                    {
                        <a onclick="location.href=encodeURI( $(this).attr('url'))" style=" cursor:pointer; color:#ff0000" url="/search?keywords=@hotKey">@hotKey</a>
                    }
                    else
                    {
                        <a onclick="location.href=encodeURI( $(this).attr('url'))" style=" cursor:pointer; " url="/search?keywords=@hotKey">@hotKey</a>
                    }
                }
            </div>
        </div>


    </div>
    <!--search end-->
</div>


<div class="nav-bar">
    <div class="nav-content">
        <div class="categorys">
            <div class="cate-all"><a>全部商品分类</a><b></b></div>
            <div class="category">
                <div class="mc">
                    @{
                        IEnumerable<Himall.Model.HomeCategorySet> categories = ViewBag.Categories;
                        IEnumerable<Himall.Model.CategoryInfo> secondCategoies = ViewBag.AllSecondCategoies;
                        int rowNumber = 0;
                    }

                    @foreach( var cateogry in categories )
                    {
                        rowNumber++;

                        if( cateogry.HomeCategories.Count() > 0 )
                        {
                            <div class="item">
                                <span>
                                    <h3>
                                        @{int j = 0;
                                        var topCategories = cateogry.HomeCategories.Where( item => item.Depth == 1 );}@foreach( var topCateory in topCategories )
                                        {
                                            if( j++ > 0 )
                                            {@("、")}<a href="@Url.Action("Index", "Search", new{cid=topCateory.CategoryId})">@topCateory.CategoryInfo.Name</a>}
                                    </h3>
                                    <s></s>
                                </span>
                                <div class="category-details">
                                    <div class="subitem">
                                        <p>
                                            @{int k = 0; }@foreach( var topCateory in topCategories )
                                            {
                                                if( k++ > 0 )
                                                {@("、")}<a href="@Url.Action("Index", "Search", new{cid=topCateory.CategoryId})">@topCateory.CategoryInfo.Name</a>}
                                        </p>
                                        @{
                                            j = 0;

                                            var subCategories = cateogry.HomeCategories.Where( item => item.Depth == 3 ).GroupBy( item => item.CategoryInfo.ParentCategoryId );
                                        }

                                        @foreach( var group in subCategories )
                                        {
                                            <dl class="@(j++ == 0 ? "first" : "")">
                                                <dt><a href="@Url.Action("Index", "Search", new { cid = secondCategoies.FirstOrDefault(item => item.Id == group.Key).Id})">@secondCategoies.FirstOrDefault( item => item.Id == group.Key ).Name</a></dt>
                                                <dd>

                                                    @foreach( var subThirdCategoy in group )
                                                    {
                                                        <em><a href="@Url.Action("Index", "Search", new { cid = subThirdCategoy.CategoryInfo .Id})">@subThirdCategoy.CategoryInfo.Name</a></em>
                                                    }
                                                </dd>
                                            </dl>
                                        }
                                    </div>
                                    @*<div class="cate-right">
                                            <dl class="categorys-promotions">
                                                @if (cateogry.HomeCategoryTopics != null)
                                                {
                                                    foreach (var topic in cateogry.HomeCategoryTopics)
                                                    {
                                                        <a target="_blank" href="@topic.Url"><img src="@topic.ImageUrl" width="194" height="70" /></a>
                                                    }
                                                }
                                            </dl>

                                            @{Dictionary<int, IEnumerable<Himall.Model.BrandInfo>> categoryBrands = ViewBag.CategoryBrands;}

                                            <dl class="categorys-brands">
                                                <h5>推荐品牌</h5>
                                                <ul>
                                                    @foreach (var brand in categoryBrands[rowNumber])
                                                    {
                                                        <li><a href="@Url.Action("Index", "Search", new { b_id = brand.Id })" target="_blank">@brand.Name</a></li>
                                                    }
                                                </ul>
                                            </dl>

                                        </div>*@
                                </div>
                            </div>
                        }

                    }

                </div>

            </div>
        </div>

        <ul class="nav cl">
            @{ IEnumerable<Himall.Model.BannerInfo> navigators = ViewBag.Navigators; }
            <li class="cur  _banner" id="homePage" index=""><a href="/">首页</a></li>
            <li class="_banner" id="limittimebuy" index="@Url.Action("home","LimitTimeBuy")"><a href="@Url.Action("home","LimitTimeBuy")">限时购</a></li>
            <li class="_banner" index="@Url.Action("list","topic")"><a href="@Url.Action("list","topic")">专题</a></li>
            <li class="_banner" id="integralmall" index="@Url.Action("Index", "IntegralMall")"><a href="@Url.Action("Index", "IntegralMall")">积分商城</a></li>
            @foreach( var navigator in navigators )
            {
                <li class="_banner" index="@navigator.Url"><a target="_blank" href="@navigator.Url">@navigator.Name</a></li>
            }
        </ul>
    </div>
</div>


<div class="right-side">
	<div class="right-side-menu">
		<ul class="menu-top">
			<li data-tag="user"> 
				<i class="user" id="right_userCenter"></i>
				<span>个人中心</span>
			</li>
			<s></s>
			<li data-tag="cart" arrow class="side-cart" id="right_cart">
				<i class="cart"></i>
				<p>购物车</p>
				<em>0</em>
			</li>
			<s></s>
            <li data-tag="asset" arrow id="right_asset">
                <i class="asset"></i>
                <span>资产中心</span>
            </li>
			<!--<li data-tag="at-shop">
				<i class="at-shop"></i>
				<span>关注店铺</span>
			</li>-->
			<li data-tag="at-goods" arrow id="right_goods">
				<i class="at-goods"></i>
				<span>关注商品</span>
			</li>
            <li data-tag="history" arrow id="right_history">
                <i class="history"></i>
                <span>浏览历史</span>
            </li>
		</ul>
		<ul class="menu-bot">
			<li>
				<i class="go-top"></i>
				<span>返回顶部</span>
			</li>
		</ul>
	</div>
	<div class="side-content">
		<div class="side-cart-c">
			<div class="side-bd">
				<input type="hidden" value="@Himall.Model.ProductInfo.ProductAuditStatus.Audited.GetHashCode()" id="hidAuditStatus" />
				<input type="hidden" value="@Himall.Model.ProductInfo.ProductSaleStatus.OnSale.GetHashCode()" id="hidSaleStatus" />
				<div class="cart-top">
					<label><input type="checkbox" name="s-checkAll" checked />全选</label>
                    <a href="/cart/cart" title="">查看全部</a>
				</div>
				<div class="cart-list">
					<ul id="side-cart-list">
						
					</ul>
				</div>
			</div>
			<div class="side-bt">
				<div class="cart-total">
					<span class="total-money">￥<em id="s-total-money">0</em></span>
					<span class="total-num">已选<em id="s-total-num">0</em>件</span>
				</div>
				<input type="button" id="toSubmitOrder" value="购物车结算">
			</div>			
		</div>
		
		<div class="side-asset-c">
			<div class="side-hd">
				<a class="side-close" title="关闭">>></a>
                <a href="/UserCenter?url=/userCoupon&tar=userCoupon" target="_blank">资产中心</a>
			</div>
			<div class="side-bd">
				<div class="side-asset-total cl">
					<div>
						<span>@ViewBag.MemberIntegral</span>
						<p>我的积分</p>
					</div>
					<div>
						<span id="mycouponcount">@(ViewBag.Coupons.Count + ViewBag.ShopBonus.Count)</span>
						<p>优惠券</p>
					</div>
				</div>
				<div class="side-asset-list">
					<p>已领取的优惠券</p>
					<ul>
                        @{var cls="";}
                        @foreach( var item in ( List<Himall.Model.UserCouponInfo> )ViewBag.Coupons )
                        {
                            if (item.Price >= 100) { cls = "coupon-lg"; }

                            else if (item.Price <= 50) { cls = "coupon-sm"; }   
                            <li class="@cls">
                                <a href="/Shop/Home/@item.ShopId" target="_blank">
									<h5>@item.ShopName</h5>
                                    @if(item.OrderAmount>0)
                                    {
                                     <h3><span>￥@item.Price</span>满@(item.OrderAmount)可用</h3>
                                    }
                                    else
                                    {
                                         <h3><span>￥@item.Price</span>满@(item.Price)可用</h3>
                                    }
                                    <p>截止@(item.EndTime.ToString("yyyy.MM.dd"))</p>
                                </a>
						    </li>
                        }

                        @{cls = "";}
                        @foreach( var item in ( List<Himall.Model.ShopBonusReceiveInfo> )ViewBag.ShopBonus )
                        {
                            if( item.Price >= 100 ) { cls = "coupon-lg"; }

                            else if( item.Price <= 50 ) { cls = "coupon-sm"; }
                            <li class="@cls">
                                <a href="/Shop/Home/@item.Himall_ShopBonusGrant.Himall_ShopBonus.ShopId" target="_blank">
                                    <h5>@item.Himall_ShopBonusGrant.Himall_ShopBonus.Himall_Shops.ShopName</h5>
                                    @if( item.Himall_ShopBonusGrant.Himall_ShopBonus.UseState == Himall.Model.ShopBonusInfo.UseStateType.FilledSend )
                                    {
                                        <h3><span>￥@item.Price</span>满@{@item.Himall_ShopBonusGrant.Himall_ShopBonus.UsrStatePrice}减@{@item.Price}优惠券</h3>
                                    }
                                    else
                                    {
                                        <h3><span>￥@item.Price</span>满@(item.Price)可用</h3>
                                    }
                                    <p>截止@(item.Himall_ShopBonusGrant.Himall_ShopBonus.BonusDateEnd.ToString( "yyyy.MM.dd" ))</p>
                                </a>
                            </li>
                        }
					</ul>


                        
				</div>
			</div>
		</div>
		
		<div class="side-atgoods-c">
			<div class="side-hd">
				<a class="side-close" title="关闭">>></a>
                <a href="/UserCenter?url=/productConcern&tar=productConcern" target="_blank">关注商品</a>
			</div>
			<div class="side-bd">
				<ul class="side-goods-list cl">
					@foreach (var item in (List<Himall.Model.FavoriteInfo>)ViewBag.Concern)
                    {
                        <li>
                            <a href="@Url.Action("Detail", "Product", new { id=@item.ProductId})" target="_blank"><img src="@item.ProductInfo.ImagePath/1_50.png" /></a>
                            <p><a href="@Url.Action("Detail", "Product", new { id=@item.ProductId})" target="_blank">@item.ProductInfo.ProductName</a></p>
                        </li>
                    }
				</ul>
			</div>
		</div>
		<div class="side-history-c">
			<div class="side-hd">
				<a class="side-close" title="关闭">>></a>
				<a href="javascript:void(0)" target="_blank">浏览历史</a>
			</div>
			<div class="side-bd">
				<ul class="side-goods-list cl">
                    @foreach( var item in ( List<Himall.Web.Areas.Web.Models.ProductBrowsedHistoryModel> )ViewBag.BrowsingProducts )
                    {
                        <li>
                            <a href="@Url.Action("Detail", "Product", new { id=@item.ProductId})" target="_blank"><img src="@item.ImagePath/1_50.png" /></a>
                            <p><a href="@Url.Action("Detail", "Product", new { id=@item.ProductId})" target="_blank">@item.ProductName</a></p>
</li>
                    }
				</ul>
			</div>
		</div>
		
	</div>
</div>

<script type="text/javascript">
	$(function(){
		//搜索切换
		$('.search-form label').click(function() {
			$(this).siblings('ul').show();
		});
		$('.search-form ul li').click(function() {
			$(this).parent().hide().siblings('label').text($(this).text());
		});
		
		//右侧菜单
		$('#right_cart em').text($('shopping-amount').text());
		
		var rightSide=$('.right-side');
		var rightContent=$('.side-content');
		$('.right-side .menu-top li[arrow]').click(function() {

		    if (!islogin ){
		        $.fn.login({}, function () {
		            location.href = "/";
		        }, '', '', '/Login/Login');
		    }else{
				
			    var tag=$(this).data('tag');
			    switch(tag){
					case 'cart':
						loadCartInfo();
					    rightContent.find('.side-cart-c').show().siblings().hide();
					    break;
				    case 'asset':
					    rightContent.find('.side-asset-c').show().siblings().hide();
					    break;
				    case 'at-goods':
					    rightContent.find('.side-atgoods-c').show().siblings().hide();
					    break;
				    case 'history':
					    rightContent.find('.side-history-c').show().siblings().hide();
					    break;
			    }
			    if (rightContent.is(':hidden')) {
				    rightContent.show();
				    rightSide.css('right','-220px').animate({right:'0'},300);
			    }
				$(this).addClass('active').siblings().removeClass('active');
		    }
		});
		
		$('.right-side-menu li').hover(function(){
			$(this).find('span').show().stop(false,true).animate({'right':40,'opacity':1},300);
		},function(){
			$(this).find('span').stop(false,true).animate({'right':60,'opacity':0},300,function(){$(this).hide()});
		});
		
		$(document).on('click', function(e){
			event = e ? e : window.event;
			var obj = event.srcElement ? event.srcElement : event.target; 
			if (! $.contains(rightSide.get(0), obj)) {
				sideRightClose();
			}
		});
		
		function sideRightClose(){
			if (rightContent.is(':visible')) {
				if(!rightSide.is(':animated')){
					rightSide.animate({right:'-220px'},200,function(){
						rightContent.hide();
						rightSide.css('right',0);
						$('.right-side .menu-top li[arrow]').removeClass('active')
					});
				}
			}
		}
		
		$('.side-close').click(function() {
			sideRightClose();
		});
		
		
		$('.go-top').click(function() {
			$('body,html').animate({'scrollTop':0},300);
		});
		
		$('.side-cart-c .cart-list').height($(window).height()-120);
		$(window).resize(function() {
			$('.side-cart-c .cart-list').height($(window).height()-120);
		});
		
		$(".side-asset-c .side-bd,.side-atgoods-c .side-bd,.side-history-c .side-bd,.side-cart-c .cart-list").niceScroll({
			cursorwidth:5,
			cursorcolor:"#616161",
			cursorborder :0,
			cursorborderradius:0
		});
		
		
		$('#toSubmitOrder').click(function() {
			var arr = [], str = '';
			$('input[name="checkItem"]').each(function (i, e) {
				if ($(e).attr('checked')) {
					arr.push($(e).data('cartid'));
				}
			});
			str = (arr && arr.join(','));
			
			if (str != "")
				location.href = '/order/submit?' + 'cartItemIds=' + str;
			else
				$.dialog.errorTips("没有可结算的商品！");
		});
		
	});
var data = {};
function loadCartInfo() {
    
    $.post('/cart/GetCartProducts', {}, function (cart) {
        data = {};
        $.each(cart.products, function (i, e) {
            if (data[e.shopId]) {
                if (!data[e.shopId]['name']) {
                    data[e.shopId]['name'] = e.shopName;
                }
                data[e.shopId]['shop'].push(e);
            } else {
                data[e.shopId] = {};
                data[e.shopId]['shop'] = [];
                data[e.shopId]['name'] = e.shopName;
                data[e.shopId]['status'] = e.productstatus;
                data[e.shopId]['shop'].push(e);
            }
        });
        var strproductstatus = $("#hidSaleStatus").val();
        var strproductauditstatus = $("#hidAuditStatus").val();
		var list='';
        if (cart.products.length > 0) {
            $.each(data, function (i, e){
				var shopPrice=0;
				var str = '';
                $.each(e.shop, function (j, product){

                    if (product.productstatus == strproductstatus) {
						if (product.productauditstatus == strproductauditstatus) {
							str += '\
							<div class="cart-list-goods cl">\
								<input class="checkbox" type="checkbox"  data-cartid="'+ product.cartItemId + '" name="checkItem" value="' + product.shopId + '" checked />';
									
							str += '\
								<a href="/product/detail/' + product.id + '" title="' + product.name + '" target="_blank"><img src="' + product.imgUrl + '" alt="" /></a>\
								<div class="s-num"><span>' + product.count + '</span></div>\
								<div class="s-g-price">'+ (product.price*product.count).toFixed(2) + '</div>\
							</div>';
							
							shopPrice=shopPrice+product.price*product.count;
						}
                    }

                    
                });
				list+='<li><div class="cart-list-shop cl">\
						<input class="shopSelect" type="checkbox" value="' + i + '" name="checkShop" checked />\
						<p><a href="/shop/home/'+ i + '" target="_blank">' + e.name + '</a></p>\
						<span class="cart-shop-price" data-shoprice="'+shopPrice.toFixed(2)+'">'+shopPrice.toFixed(2)+'</span>\
						</div>'+str+'</li>';
				
            });
            $('#side-cart-list').html(list);
            $('#s-total-num').html(cart.totalCount);
            $('#s-total-money').html(cart.amount.toFixed(2));
            bindSelectAll();
        }
    });

    
}

function bindSelectAll() {
    $('input[name="s-checkAll"]').change(function () {
        var checked = this.checked;
		$('#side-cart-list input[type=checkbox]').prop('checked',this.checked);
        if (checked) {
            $('#s-total-money').html(getCheckProductPrice());
			$('#side-cart-list li').each(function() {
				var shopP=$(this).find('.cart-shop-price');
				shopP.html(shopP.data('shoprice').toFixed(2));
			});
        }
        else {
            $('#s-total-money').html("0.00");
			$('#side-cart-list .cart-shop-price').html("0.00");

        }
        $('#s-total-num').html(getCheckProductCount());
    });

    $('input[name="checkShop"]').change(function () {
        var checked = this.checked;
		var total = $(this).siblings('.cart-shop-price').html();
		$(this).parent().siblings().find('input[type="checkbox"]').prop('checked', checked);
		
        var allShopChecked = true;
        $('#side-cart-list input[type="checkbox"]').each(function () {
            if (!$(this).prop('checked')) {
                allShopChecked = false;
            }
        });
        if (allShopChecked)
            $('input[name="s-checkAll"]').prop('checked', true);
        else
            $('input[name="s-checkAll"]').prop('checked',false);
		
		var t = 0;
		$.each($(this).parent().siblings(), function () {
			var a = $(this).find('input[name="checkItem"]:checked').siblings('.s-g-price').html();
			t += (+a);
		})
		$(this).siblings('.cart-shop-price').html(t.toFixed(2));
		$('#s-total-money').html(getCheckProductPrice());
        $('#s-total-num').html(getCheckProductCount());
    });

    $('input[name="checkItem"]').change(function () {
        var checked = this.checked;
        if (checked)
            $(this).prop('checked', checked);
        else
            $(this).removeAttr('checked');

        //判断店铺下的所有商品是否全选中
        var allProductChecked = true;
		$(this).parent().siblings('.cart-list-goods').each(function() {
			if (!$(this).find('input').prop('checked'))
                    allProductChecked = false;
		});
        if (allProductChecked)
            $(this).parent().siblings().find('input[name="checkShop"]').prop('checked', checked);
        else
			$(this).parent().siblings().find('input[name="checkShop"]').removeAttr('checked');;

        //判断所有店铺是否都选中了
        var allShopChecked = true;
        $('#side-cart-list input[type="checkbox"]').each(function (i, e) {
            if (!$(this).prop('checked')) {
                allShopChecked = false;
            }
        });
        if (allShopChecked)
            $('input[name="s-checkAll"]').prop('checked', true);
        else
            $('input[name="s-checkAll"]').removeAttr('checked');

		var t = 0;
		$.each($(this).parents('li').find('input[name="checkItem"]:checked'), function () {
			var a = $(this).siblings('.s-g-price').html();
			t += (+a);
		})
		$(this).parent().siblings('.cart-list-shop').find('.cart-shop-price').html(t.toFixed(2));
		
        $('#s-total-money').html(getCheckProductPrice());
        $('#s-total-num').html(getCheckProductCount());
    });

}


function getCheckProductPrice() {
    var t = 0;
    $.each($('input[name="checkItem"]:checked'), function () {
        var a = $(this).siblings('.s-g-price').html();
        t += (+a);
    })
    return t.toFixed(2);
}

function getCheckProductCount() {
    var t = 0;
    $.each($('input[name="checkItem"]:checked'), function () {
        var c = $(this).siblings('.s-num').children().html();
        d = parseInt(c);
        t += d;
    })
    return t;
}


</script>


<script>

    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    var islogin = @ViewBag.isLogin;
    function getQueryString(name)
    {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }

    function InitialBanner()
    {
        var isSelect = false;
        $("._banner").each(function ()
        {
            $(this).removeClass("cur");
            if ($(this).attr("index") === window.location.href)
            {
                $(this).addClass("cur");
                isSelect = true;
            }
            if ($(this).attr("index").indexOf("/LimitTimeBuy/") >= 0
                && window.location.href.indexOf("/LimitTimeBuy/") >= 0)
            {
                $(this).addClass("cur");
                isSelect = true;
            }
            else{
                if ($(this).attr("index").toLowerCase().indexOf("/topic/list") >= 0
                && window.location.href.toLowerCase().indexOf("/topic/list") >= 0)
                {
                    $(this).addClass("cur");
                    isSelect = true;
                }
            }

            if ($(this).attr("index").indexOf("/IntegralMall") >= 0
                && window.location.href.toLowerCase().indexOf("/integralmall") >= 0)
            {
                $(this).addClass("cur");
                isSelect = true;
            }
        });

        if (!isSelect)
        {
            $("#homePage").addClass("cur");
        }
    }

    $(function ()
    {

        //isPCurl();
        InitialBanner();
        //  bindCartItemDelete();
        //refreshCartProducts();


        //商品导航
        //$('.categorys .item').hover(function () {
        //    $(this).toggleClass('hover');
        //})
        if ($('.category').css('display') == 'none')
        {
            $('.categorys').mouseDelay().hover(function ()
            {
                $('.category').show();
            });
            $('.categorys').mouseleave(function ()
            {
                $('.category').hide();
            });
        }

        ////下拉菜单
        //$('.dropdown').hover(function () {
        //    $(this).toggleClass('hover');
        //});

        function queryForm(pageNo)
        {
            var keyWords = $('#searchBox').val();
            var exp_keyWords = $("#text-stock-search").val();
            var cid = getQueryString('cid');
            var b_id = getQueryString('b_id');
            var orderType = getQueryString('orderType');
            var orderKey = getQueryString('orderKey');
            location.href = "/search?pageNo=" + pageNo + "&keywords=" + encodeURIComponent(keyWords ? keyWords : $('#searchBox').attr('placeholder'))
                                    + "&exp_keywords=" + exp_keyWords + "&cid=" + cid + "&b_id=" + b_id + "&orderType=" + orderType
                                    + "&orderKey=" + orderKey;
        }

        $('#searchBtn').click(function ()
        {
            var keyWords = $.trim($('#searchBox').val());

            var selected = $(".search .search-form label").html();
            if(selected == "店铺")
            {
                if(keyWords == '')
                {
                    return;
                }
                location.href = "/shopsearch?keywords=" + encodeURIComponent(keyWords ? keyWords : $('#searchBox').attr('placeholder'))
            }
            else
            {
                location.href = "/search?keywords=" + encodeURIComponent(keyWords ? keyWords : $('#searchBox').attr('placeholder'))
            }
            
        });

        $("#searchBox").keydown(function (e) {
            if (e.keyCode == 13) {
                var keyWords = $.trim($('#searchBox').val());

                var selected = $(".search .search-form label").html();
                if(selected == "店铺")
                {
                    if(keyWords == '')
                    {
                        return;
                    }
                    location.href = "/shopsearch?keywords=" + encodeURIComponent(keyWords ? keyWords : $('#searchBox').attr('placeholder'))
                }
                else
                {
                    location.href = "/search?keywords=" + encodeURIComponent(keyWords ? keyWords : $('#searchBox').attr('placeholder'))
                }
            }
        });

        $('#btn-re-search').click(function ()
        {
            var keyWords = $('#key-re-search').val();
            location.href = "/search?keywords=" + encodeURIComponent(keyWords);
        });

        $('#btn-stock-search').click(function ()
        {
            queryForm(1);
        });

        $('#pageJump').click(function ()
        {
            var pageNo = parseInt($("#jumpInput").val());
            var pagecount = parseInt($("#pageCount").html());
            if (pageNo > pagecount || pageNo < 1)
            {
                alert("请您输入有效的页码!");
                return;
            }
            if (isNaN(pageNo)) {
                pageNo = 1;
            }
            queryForm(pageNo);
        } );

        $("#right_cart").click(function () {
            //location.href = "/cart/cart";
            //window.open("/cart/cart");
        });

        $("#right_userCenter").click(function () {
            if (islogin) {
                window.open("/usercenter");
            }
            else {
                $.fn.login({}, function () {
                    location.href = "/";
                }, '', '', '/Login/Login');
            }
        });


});

    //function isPCurl()
    //{
    //    var ua = window.navigator.userAgent.toLowerCase();
    //    //bIsAndroid = true;
    //    if ((bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {
    //        if (ua.match(/MicroMessenger/i) == 'micromessenger' && location.href.toLowerCase().indexOf('/m-wap') == -1 && location.href.toLowerCase().indexOf('/m-weixin') == -1) {
    //            var url='';
    //            var arr = location.href.toLowerCase().split('/');
    //            for (var i = 0; i < arr.length; i++) {
    //                url = url + arr[i] + '/';
    //                if (i == 2)
    //                    url = url + 'm-weixin/'
    //            }
    //            isErrorURL(url.substring(0, url.length - 1), '/m-weixin');
    //        }
    //        else if (ua.match(/MicroMessenger/i) != 'micromessenger' && location.href.toLowerCase().indexOf('/m-wap') == -1 && location.href.toLowerCase().indexOf('/m-weixin') == -1) {
    //            var url='';
    //            var arr = location.href.toLowerCase().split('/');
    //            for (var i = 0; i < arr.length; i++) {
    //                url = url + arr[i] + '/';
    //                if (i == 2)
    //                    url = url + 'm-wap/'
    //            }
    //            isErrorURL(url.substring(0, url.length - 1), '/m-wap');
    //        }
    //    }
    //}


    //function refreshCartProducts() {
    //    $.post('/cart/GetCartProducts', {}, function (cart) {
    //        var products = cart.products;
    //        var count = cart.totalCount;
    //        $('#shopping-amount,#cartProductsCount').html(count);
    //        if (count) {
    //            $('#cartEmpty').hide();
    //            $('#cartProducts').show();
    //            var html = '';
    //            $.each(products, function (i, product) {
    //                html += ' <li>\
    //                        <div class="p-img fl">\
    //                            <a href="/product/detail/' + product.id + '" target="_blank"><img src="' + product.imgUrl + '" width="50" height="50" alt=""></a>\
    //                        </div>\
    //                        <div class="p-name fl"><a href="/product/detail/' + product.id + '" title="" target="_blank">' + product.name + '</a></div>\
    //                        <div class="p-detail fr ar"><span class="p-price"><strong>￥' + product.price.toFixed("2") + '</strong>×' + product.count + '</span><br><a class="delete" skuId="' + product.skuId + '" href="javascript:;">删除</a></div>\
    //                    </li>';
    //            });
    //            $('#productsList').html(html);
    //            $('#cartAmount').html(cart.amount.toFixed("2"));
    //        }
    //        else {
    //            $('#cartEmpty').show();
    //            $('#cartProducts').hide();
    //        }
    //    });
    //}

    function bindCartItemDelete()
    {
        $('#productsList').on('click', 'a.delete', function ()
        {
            var skuId = $(this).attr('skuId');
            removeFromCart(skuId);
        });
    }

    function removeFromCart(skuId)
    {
        $.post('/cart/RemoveFromCart', { skuId: skuId }, function (result)
        {
            if (result.success)
                refreshCartProducts();
            else
                alert(result.msg);
        });
    }

    //function isErrorURL(url,platform)
    //{
    //    $.ajax({
    //        type: "GET",
    //        cache: false,
    //        url: ""+url+"",
    //        data: "",
    //        success: function () {
    //            location.href=url;
    //        },
    //        error: function () {
    //            location.href = '//'+location.host + platform;
    //        }
    //    });
    //}
</script>